<template>
  <Layout>
    <Form ref="form1" :model="dataToQuery" :label-width="160">
      <Row class="query-form" v-if="!modelTcheme">
        <Col span="8">
          <FormItem label="二级集团：" prop="twoLevelOrgName">
            <Select v-model="dataToQuery.twoLevelOrgName" filterable>
              <Option v-for="item in twoLevelOrgs" :value="item.orgName" :key="item.orgId">{{ item.orgName }}</Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="8">
          <FormItem label='企业名称：'>
            <Select clearable filterable style="width:300px" v-model="dataToQuery.companyName" placeholder="请选择企业"
                    :remote-method="remoteMethodSelectOrg"
                    :default-label="defaultLabel"
                    :loading="orgLoading">
              <Option v-for="(option, index) in orgLists" :value="option.orgName" :key="index">{{ option.orgName }}
              </Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="8" v-if="!switchFlag">
          <Button @click="switchQuery(true)" class="ivu-btn-switch" type="text">展开∨</Button>
          <Button @click="reset" class="ivu-btn-reset">重置</Button>
          <Button type="primary" class="ivu-btn-query" icon="md-search" @click="query">查询</Button>
        </Col>
        <Col span="8" v-else>
          <FormItem label="是否构成重大危险源：">
            <Select v-model='dataToQuery.ifHazard' placeholder="请选择是否清库" class='query-form-el'>
              <Option value="是">是</Option>
              <Option value="否">否</Option>
            </Select>
          </FormItem>
        </Col>
      </Row>
      <Row v-show="switchFlag" class="query-form">
        <Col span="8">
          <FormItem label="存储位置/库房：">
            <Input class="query-form-el" type="text" v-model="dataToQuery.warehouse"></Input>
          </FormItem>
        </Col>
        <Col span="8" offset="8">
          <Button @click="switchQuery(false)" class="ivu-btn-switch" type="text">收起∧</Button>
          <Button @click="reset" class="ivu-btn-reset">重置</Button>
          <Button class="ivu-btn-query" icon="md-search" @click="query">查询</Button>
        </Col>
      </Row>
      <Row class="query-form" v-if="!modelTcheme">
        <Col span="24">
          <Button size="large" class="ivu-btn-add" icon="md-add" @click="addInfo">新增</Button>
          <download-button :api="exportUrl" :queryForm="dataToQuery" />
          <!-- <Button type="primary" class="ivu-btn-add" icon="md-cloud-download" @click="exportFormSubmit">导出</Button> -->
        </Col>
      </Row>
    </Form>
    <Table ref='table' :height="tableHeight" no-data-text="没有查询到相关数据!" @on-selection-change='getSelectRows'
    @on-sort-change="sortChange" :loading='pageStatus.loading'
           border :columns="columns1" :data="dataTable">
    </Table>
    <Row style="margin-right:10px;">
      <Col span="24">
        <Page style="float: right" :total="pagedata.total" :page-size="pagedata.pageSize"
              @on-change="pageChange" @on-page-size-change="pageSizeChange" :page-size-opts="pageSizeArray"
              show-total show-sizer show-elevator/>
      </Col>
    </Row>

    <!--<Form v-if="modelTcheme" ref="form2" :model="form2" :label-width="120">-->
    <!--<Row class="query-form" style="padding-top: 5px">-->
    <!--<Col span="23">-->
    <!--<FormItem label="已选择危化品库：">-->
    <!--<TagInput ref="refTagInput" :tags="selectHcmInfos"/>-->
    <!--</FormItem>-->
    <!--</Col>-->
    <!--<Col span="23">-->
    <!--<Button class='ivu-btn-save' @click="closeModal">确定</Button>-->
    <!--</Col>-->
    <!--</Row>-->
    <!--</Form>-->

    <Modal :title="this.getModalTitle('危化品')" :transfer=false :mask-closable="false" v-model="dialogShow"
           v-if="dataToView && dialogShow" :width=800 class-name='limit-height-dialog'>
      <Row>
        <Col span="24">
          <Form ref="dialogForm" :class="mode === 'view'?'modal-view-detail':''" :show-message="false"
                :model="dataToView" :rules="mode === 'view'?{}:ruleCustom"
                :label-width="mode === 'view'?140:null" :label-position="mode === 'view'?'right':'top'">
            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="11">
                <FormItem label='单位名称：' prop='companyId'>
                  <div v-if="mode === 'view'">{{ dataToView.companyName }}</div>
                  <div v-else>
                    <cascader-dom class='query-form-el' ref='orgCascader' @setOrgInfo='setCompanyId'
                                  @setOrgname="setCompanyName" :orgTree="true"
                                  :currentOrgId="dataToView.companyId" :rootOrgId="dataToView.belongOrgId"
                                  :setCurrentName="{label:dataToView.companyName,value:dataToView.companyId}"></cascader-dom>
                  </div>
                </FormItem>
              </Col>
              <Col span="11">
                <FormItem label='存储位置/(库房)：' prop='warehouse'>
                  <div v-if="mode === 'view'">{{ dataToView.warehouse }}</div>
                  <Input v-else class='query-form-el' placeholder="请填写存储位置/(库房)" show-word-limit
                         maxlength="100" type='text' v-model='dataToView.warehouse'></Input>
                </FormItem>
              </Col>
            </Row>
            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="11">
                <FormItem label='占地面积：' prop='areaCovered'>
                  <div v-if="mode === 'view'">{{ dataToView.areaCovered }}</div>
                  <InputNumber v-else class='query-form-el' placeholder="请填写占地面积" :min="0" type='text'
                               v-model='dataToView.areaCovered'></InputNumber>
                </FormItem>
              </Col>
              <Col span="11">
                <FormItem label='库房负责人：' prop='chargeUser'>
                  <div v-if="mode === 'view'">{{ dataToView.chargeUserName }}</div>
                  <!--<Input v-else class='query-form-el' placeholder="请填写库房负责人" type='text' v-model='dataToView.chargeUser'></Input>-->
                  <div v-else>
                    <userDom ref="userDom" :selectData='setCurrentUserName' :singleChoice=true :ifUser="true"
                             :rootOrgName="dataToView.companyName"
                             class='query-form-el'
                             @setData='(data)=>{ if(data){this.$set(dataToView, "chargeUser", data.userId),this.$set(dataToView, "chargeUserName", data.userName)}}'></userDom>
                  </div>
                </FormItem>
              </Col>
            </Row>
            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="11">
                <FormItem label='负责人电话 ：' prop='chargeTelphone'>
                  <div v-if="mode === 'view'">{{ dataToView.chargeTelphone }}</div>
                  <Input v-else class='query-form-el' placeholder="请填写负责人电话 " type='text'
                         v-model='dataToView.chargeTelphone'></Input>
                </FormItem>
              </Col>
              <Col span="11">
                <FormItem label="是否构成重大危险源：" prop='ifHazard'>
                  <div v-if="mode === 'view'">{{ dataToView.ifHazard }}</div>
                  <Select v-else v-model='dataToView.ifHazard' placeholder="请选择是否清库" class='query-form-el'>
                    <Option value="是">是</Option>
                    <Option value="否">否</Option>
                  </Select>
                </FormItem>
                <!--<FormItem label='所属范围：' prop='scope'>-->
                <!--<div v-if="mode === 'view'">{{ dataToView.scope }}</div>-->
                <!--<Input v-else class='query-form-el' placeholder="请填写所属范围" show-word-limit maxlength="200" type='text' v-model='dataToView.scope'></Input>-->
                <!--</FormItem>-->
              </Col>
            </Row>

            <Row>
              <Col span="23" class="query-form" style="margin-left: 15px">
                <Button v-if="mode !== 'view'" class="ivu-btn-add" icon="md-add"
                        @click="itemModel=true,itemAdd=true;detailItem={hcmCount:0,hcmCountPro:'kg',}">新增危化品
                </Button>
                <Table highlight-row stripe border style="margin-top:10px;margin-bottom: 10px" :max-height="350"
                       :columns="itemColumn"
                       :data="dataToView.items">
                </Table>
              </Col>

            </Row>

            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="23">
                <FormItem label="安全措施说明：">
                  <div v-if="mode === 'view'">{{ dataToView.notes }}</div>
                  <Input v-else v-model="dataToView.notes" type="textarea" show-word-limit maxlength="300"
                         :autosize="{minRows:2,maxRows:5}"/>
                </FormItem>
              </Col>
            </Row>
            <Row type="flex" justify="space-around"
                 class="code-row-bg">
              <Col span="23">
                <FormItem v-if="mode === 'view'" label="安全措施说明附件：">
                  <div v-show="dataToView.idFiles.length>0" v-for="(item,index) in dataToView.idFiles">
                    <a @click="downloadFiles(item,index)"><span style="color: #3399ff;margin-left: 5px">{{
                        item.fileName
                      }}</span></a>
                    <Progress v-show="uploadListVisible[index]" :percent="uploadListPercent[index]"></Progress>
                  </div>
                </FormItem>
                <FormItem v-else label="安全措施说明附件：" prop="idFiles">
                  <div>
                    <Upload ref="upload"
                            :before-upload="(file) => { beforeUpload1(file, 'id', 'hcmInfo') }"
                            :show-upload-list="true"
                            :max-size="10240"
                            multiple
                            type="drag"
                            :action="fileUrl">
                      <div style="padding: 10px">
                        <Icon type="ios-cloud-upload" size="45" style="color: #3399ff"></Icon>
                        <p>点击将文件拖拽到这里上传</p>
                      </div>
                    </Upload>
                  </div>
                  <div v-show="dataToView.idFiles.length>0" v-for="(item,index) in dataToView.idFiles" :key='item'>
                    <a @click="downloadFiles(item,index)">{{ item.fileName }}</a>
                    <Button type="text" icon="md-trash" @click="removeFile1(item.id, 'id', 'hcmInfo')"
                            style="margin-left: 5px;margin-bottom: 3px"/>
                    <Progress v-show="uploadListVisible[index]" :percent="uploadListPercent[index]"></Progress>
                  </div>
                </FormItem>
              </Col>
            </Row>
            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="11">
                <FormItem label='填报人：' prop='createUserName'>
                  <div v-if="mode === 'view'">{{ dataToView.createUserName }}</div>
                  <Input v-else class='query-form-el' placeholder="请填写填报人" type='text' readonly
                         v-model='dataToView.createUserName'></Input>
                </FormItem>
              </Col>
              <Col span="11">
                <FormItem label='填报时间：' prop='createDate'>
                  <div v-if="mode === 'view'">{{ renderViewDate(dataToView.createDate) }}</div>
                  <DatePicker v-else class="query-form-el" placeholder="请选择填报时间" readonly
                              v-model='dataToView.createDate'></DatePicker>
                </FormItem>
              </Col>
            </Row>
            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="11">
                <FormItem label='填报人手机号：' prop='registrantPhone'>
                  <div v-if="mode === 'view'">{{ dataToView.registrantPhone }}</div>
                  <Input v-else class='query-form-el' placeholder="请填写填报人手机号" type='text'
                         v-model='dataToView.registrantPhone'></Input>
                </FormItem>
              </Col>
              <Col span="11"></Col>
            </Row>
          </Form>
        </Col>
      </Row>
      <div slot="footer">
        <Button v-if="mode != 'view'" type="primary" class='ivu-btn-save' @click="submit('dialogForm')">确定</Button>
        <Button v-if="mode != 'view'" type="primary" class='ivu-btn-cancel' @click="handleCancel">取消</Button>
        <Button v-if="mode === 'view'" class='ivu-btn-save' @click="dialogShow=false">关闭</Button>
      </div>
    </Modal>

    <Modal :mask-closable="false" :transfer=false v-model="itemModel" :width=750 title="危化品"
           @on-cancel="itemModel=false,detailItem={}">
      <Row>
        <Col span="24">
          <Form ref="itemForm" :class="'modal-form'" :show-message="false" :model="detailItem" :rules="itemRuleCustom"
                label-position="top">
            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="11">
                <FormItem label="危化品名称：" prop="hcmName">
                  <div v-if="mode === 'view'">{{ detailItem.hcmName }}</div>
                  <Input v-else class='query-form-el' type="text" show-word-limit maxlength="100"
                         v-model="detailItem.hcmName"></Input>
                </FormItem>
              </Col>
              <Col span="11">
                <FormItem label="危化品种类：" prop="hcmType">
                  <div v-if="mode === 'view'">{{ dataToView.hcmTypeName }}</div>
                  <Select v-else class="query-form-el" v-model="detailItem.hcmType" label-in-value
                          @on-change='hcmTypeChange'>
                    <Option v-for="item in dictMap.hcmTypes" :value="item.codingCodeId" :key="item.codingCodeId">
                      {{ item.codingName }}
                    </Option>
                  </Select>
                </FormItem>
              </Col>
            </Row>
            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="11">
                <FormItem label='储存量：' prop='hcmCount'>
                  <div v-if="mode === 'view'">{{ detailItem.hcmCount + detailItem.hcmCountPro }}</div>
                  <Input v-else class='query-form-el' placeholder="请填写储存量" v-model='detailItem.hcmCount'>
                    <Select v-model="detailItem.hcmCountPro" slot="append" style="width: 70px">
                      <Option value="kg">kg</Option>
                      <Option value="ml">ml</Option>
                    </Select>
                  </Input>
                </FormItem>
              </Col>
              <Col span="11">
                <FormItem label='主要用途：' prop='mainPurpose'>
                  <div v-if="mode === 'view'">{{ detailItem.mainPurpose }}</div>
                  <Input v-else class='query-form-el' placeholder="请填写主要用途" type='text' show-word-limit
                         maxlength="200" v-model='detailItem.mainPurpose'></Input>
                </FormItem>
              </Col>
            </Row>

          </Form>
        </Col>
      </Row>
      <div slot="footer">
        <Button type="primary" class='ivu-btn-save' @click="itemSubmit('itemForm')">确定</Button>
        <Button type="primary" class='ivu-btn-cancel' @click="itemModel=false,detailItem={}">取消</Button>
      </div>
    </Modal>
  </Layout>
</template>

<script>
import {Api} from '@/api/index.js'
import {formatDate} from '@/tools/index'

var cascaderDom = () => import('@/components/cascader-dom.vue');
import pageCommonFunction from '@/components/pageCommonFunction.js'
import {sessionStorage, cookie} from '@/common/cacheUtils.js';
import userDom from "@/components/input-user.vue";
import _deepclone from 'lodash/cloneDeep'
import TagInput from "@/components/TagInput.vue"

export default {
  components: {cascaderDom, userDom, TagInput},
  props: ['companyId', 'modelTcheme', 'selectHcmInfos'],
  data() {
    return {
      ...this.createCommonDataField(),
      defaultLabel: sessionStorage('userId').getObject('userId').companyName,
      orgLists: [],
      userInfo: sessionStorage('userId').getObject('userId'),
      twoLevelOrgs: [],
      orgLoading: false,
      switchFlag: false,
      columns1: [
        {title: '序号', width: 70, fixed: 'left', align: 'center', render: this.indexColumnsRender},
        {key: 'companyName', title: '所属单位', align: 'center', minWidth: 150,},
        // { key:'hcmName',title: '危化品名称',  align: 'center', minWidth: 120, },
        // { key:'hcmTypeName',title: '危化品种类',  align: 'center', minWidth: 120, },
        {key: 'warehouse', title: '存储位置/(库房)', align: 'center', minWidth: 120, tooltip: true},
        {key: 'areaCovered', title: '占地面积', align: 'center', minWidth: 120,},
        {key: 'chargeUserName', title: '库房负责人', align: 'center', minWidth: 120,},
        {key: 'chargeTelphone', title: '负责人电话', align: 'center', minWidth: 120,},
        {key: 'ifHazard', title: '是否构成重大危险源', align: 'center', minWidth: 120,},
        // { key:'scope',title: '所属范围',  align: 'center', minWidth: 120, },
        // { key:'hcmCount',title: '储存量',  align: 'center', minWidth: 120,
        //     render: (h,params)=>{return h('span',params.row.hcmCount+params.row.hcmCountPro)}},
        // { key:'mainPurpose',title: '主要用途',  align: 'center', minWidth: 120, },
        {key: 'notes', title: '安全措施说明', align: 'center', minWidth: 120, tooltip: true},
        {key: 'createDate', title: '填报时间',sortable: "custom", align: 'center', minWidth: 120, render: this.renderCellDate},
        // { key:'registrantPhone',title: '填报人手机号',  align: 'center',minWidth: 120, },
        // this.getActionColumns(),
        {
          title: '操作',
          key: 'action',
          fixed: 'right',
          width: this.modelTcheme ? 80 : 160,
          align: 'center',
          render: (h, params) => {
            if (this.modelTcheme) {
              return h('div', [
                h('A', {
                  props: {type: 'primary', size: 'small'},
                  style: {fontSize: '12px'},
                  on: {
                    click: () => {
                      this.$emit('getActivityData', params.row);
                      // this.checkSave(params.row);
                    }
                  }
                }, '选择'),
              ]);
            } else {
              if ((this.currentUser.loginId === this.Common.admin || this.currentUser.userId === params.row.createUserId || this.currentUser.userRole.find(obj => obj.roleId == '73b38b37dff64392ba0ee7dd579bf293') != undefined
                  || sessionStorage('userId').getObject('userId').userBeHandedOver.find(obj => obj == params.row.createUserId) != undefined)) {
                return h('div', [
                  h('A', {
                    props: {type: 'primary', size: 'small'},
                    style: {fontSize: '14px',},
                    on: {
                      click: () => {
                        this.viewData(params);
                      }
                    }
                  }, '详情'),
                  h('Divider', {props: {type: 'vertical'}}, ''),
                  h('A', {
                    props: {type: 'primary', size: 'small'},
                    disabled: true,
                    style: {fontSize: '14px'},
                    on: {
                      click: () => {
                        this.editData(params);
                      }
                    }
                  }, '修改'),
                  h('Divider', {props: {type: 'vertical'}}, ''),
                  h('A', {
                    props: {type: 'primary', size: 'small'},
                    style: {fontSize: '14px', color: 'red'},
                    on: {
                      click: () => {
                        this.deleteData(params);
                      }
                    }
                  }, '删除')
                ]);
              } else {
                return h('div', [
                  h('A', {
                    props: {type: 'primary', size: 'small'},
                    style: {fontSize: '14px',},
                    on: {
                      click: () => {
                        this.viewData(params);
                      }
                    }
                  }, '详情'),
                  h('Divider', {props: {type: 'vertical'}}, ''),
                  h('A', {
                    props: {type: 'primary', size: 'small'},
                    style: {fontSize: '14px', color: '#c5c8ce'}
                  }, '修改'),
                  h('Divider', {props: {type: 'vertical'}}, ''),
                  h('A', {
                    props: {type: 'primary', size: 'small'},
                    style: {fontSize: '14px', color: '#c5c8ce'}
                  }, '删除')
                ]);
              }
            }
          }
        }
      ],
      ruleCustom: {
        companyId: [{required: true, message: '请填写所属单位', trigger: 'change',}],
        hcmName: [{required: true, message: '请填写危化品名称', trigger: 'change',}],
        hcmType: [{required: true, message: '请填写危化品种类', trigger: 'change',}],
        warehouse: [{required: true, message: '请填写存储位置/(库房)', trigger: 'change',}],
        areaCovered: [{required: true, message: '请填写占地面积', trigger: 'change', type: 'number'}],
        chargeUser: [{required: true, message: '请填写库房负责人', trigger: 'change',}],
        chargeTelphone: [{
          validator: (rule, value, callback) => {
            if (!(/^1[3456789]\d{9}$/.test(this.dataToView.chargeTelphone))) {
              callback(' ');
              // this.$Message.error("请填写有效的的手机号")
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'blur'
        }],
        // scope: [ { required: true, message: '请填写所属范围', trigger: 'change',}],
        hcmCount: [
          // { required: true, message: '请填写储存量', trigger: 'change'},
          {required: true, pattern: /(\d+(\.\d+)?)/, message: '储存量必须为数字', trigger: 'change'}],
        mainPurpose: [{required: true, message: '请填写主要用途', trigger: 'change',}],
        notes: [{required: true, message: '请填写安全措施说明', trigger: 'change',}],
        createUserName: [{required: true, message: '请填写填报人', trigger: 'change',}],
        createDate: [{required: true, message: '请填写填报时间', trigger: 'change', type: 'date'}],
        registrantPhone: [{
          validator: (rule, value, callback) => {
            if (!(/^1[3456789]\d{9}$/.test(this.dataToView.registrantPhone))) {
              callback(' ');
              // this.$Message.error("请填写有效的的手机号")
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'blur'
        }],
        idFiles: [{
          validator: (rule, value, callback) => {
            if (this.dataToView.idFiles.length < 1) {
              callback('附件必须上传')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }]
      },
      queryUrl: Api.hcmInfoList,
      exportUrl: Api.hcmInfoList + '/export',
      deleteUrl: Api.hcmInfoDelete,
      getUrl: Api.getHcmInfo,
      updateUrl: Api.hcmInfoUpdate,
      saveUrl: Api.hcmInfoAdd,

      tableHeight: 10,
      dictMap: {},
      detailItem: {},
      itemModel: false,
      itemAdd: false,
      columns2: [
        {title: '序号', width: 70, align: 'center', render: this.indexColumnsRender},
        {key: 'hcmName', title: '危化品名称', align: 'center', minWidth: 120,},
        {key: 'hcmTypeName', title: '危化品种类', align: 'center', minWidth: 120,},
        {
          key: 'hcmCount', title: '储存量', align: 'center', minWidth: 120,
          render: (h, params) => {
            return h('span', params.row.hcmCount + params.row.hcmCountPro)
          }
        },
        {key: 'mainPurpose', title: '主要用途', align: 'center', minWidth: 120,},
        {
          title: '操作',
          key: 'action',
          fixed: 'right',
          width: 110,
          align: 'center',
          render: (h, params) => {
            return h('div', [
              h('A', {
                props: {type: 'primary', size: 'small'},
                style: {fontSize: '13px',},
                on: {
                  click: () => {
                    this.detailItem = {...params.row}
                    this.itemModel = true
                    this.itemAdd = false
                  }
                }
              }, '修改'),
              h('Divider', {props: {type: 'vertical'}}, ''),
              h('A', {
                props: {type: 'primary', size: 'small'},
                style: {fontSize: '13px', color: 'red'},
                on: {
                  click: () => {
                    this.dataToView.items.splice(params.index, 1)
                  }
                }
              }, '删除'),
            ])
          }
        }
      ],
      itemRuleCustom: {
        hcmName: [{required: true, message: '请填写危化品名称', trigger: 'change',}],
        hcmType: [{required: true, message: '请填写危化品种类', trigger: 'change',}],
        hcmCount: [
          // { required: true, message: '请填写储存量', trigger: 'change'},
          {required: true, pattern: /(\d+(\.\d+)?)/, message: '储存量必须为数字', trigger: 'change'}],
        mainPurpose: [{required: true, message: '请填写主要用途', trigger: 'change',}],
      },

      currentUser: JSON.parse(sessionStorage('userId').get('userId')),
      setCurrentUserName: {},
      show: false,
      form2: {
        ids: '',
        hcmNames: '',
      },

    }
  },
  computed: {
    itemColumn() {
      const columns = [...this.columns2];
      const columns1 = []
      columns.forEach(item => {
        if (this.mode !== 'view') {
          columns1.push(item)
        } else {
          if (item.key !== 'action') {
            columns1.push(item)
          }
        }
      })
      return columns1
    },
  },
  async mounted() {
    this.queryTwoOrgInfo();
    this.setTableHeight();
    this.query();
    this.$http.get(Api.queryCodeDetailBySortId + '/HCM-000001', {params: {}}).then((res) => {
      this.dictMap.hcmTypes = res.data.data
    });
  },
  methods: {
    ...pageCommonFunction,
    queryTwoOrgInfo() {
      if (sessionStorage('userId').getObject('userId').companyId != '18000000') {
        this.twoLevelOrgs.push({
          orgId: sessionStorage('userId').getObject('userId').twoLevelOrgId,
          orgName: sessionStorage('userId').getObject('userId').twoLevelOrgName
        });
      } else {
        this.$http.get(Api.quqeryTwoOrgInfo).then(res => {
          this.twoLevelOrgs = res.data.data
        }).catch(e => {
        })
      }
    },
    remoteMethodSelectOrg(query) {
      if (query !== '') {
        this.orgLists = [];
        this.orgLoading = true;
        this.$http.get(Api.queryOrgList + "?companyId=" + this.userInfo.companyId + "&orgName=" + query + "&fromPage=1&pageSize=1000").then(res => {
          this.orgLists = res.data.data;
          this.orgLoading = false;
        }).catch(e => {
          this.orgLoading = false;
          this.$Message.error('请求失败');
        })
      } else {
        this.orgLoading = false;
      }
    },
    checkSave(row) {
      let hcmName = row.warehouse
      let id = row.id
      let hcmNameInfo = {name: hcmName, userId: id}
      let exist = false
      this.selectHcmInfos.forEach(v => {
        if (v.userId == id) {
          exist = true
        }
      })
      if (!exist) {
        this.selectHcmInfos.push(hcmNameInfo)
      }
    },
    closeModal() {
      let ids = []
      let hcmNames = []
      this.selectHcmInfos.forEach(v => {
        ids.push(v.userId)
        hcmNames.push(v.name)
      })
      this.$emit('getActivityData', {ids, hcmNames});
      this.$emit('closeModal1');
    },

    hcmTypeChange(appStatus) {
      if (appStatus) {
        this.detailItem.hcmType = appStatus.value;
        this.detailItem.hcmTypeName = appStatus.label;
      }
    },
    itemSubmit(name) {
      this.$refs[name].validate((valid) => {
        if (valid) {
          this.$Modal.confirm({
            title: '提示',
            content: '<p>是否要提交？</p>',
            onOk: () => {
              let _this = this
              _this.dataToView.items.splice()
              if (_this.itemAdd) {
                _this.dataToView.items.push(_this.detailItem)
              } else {
                _this.dataToView.items[_this.detailItem._index] = _this.detailItem
              }
              _this.itemModel = false
            },
            onCancel: () => {
            }
          })
        } else {
          this.$Message.error('请填报完整!');
        }
      })
    },

    deleteData(params) {
      this.deleteDateAjax(params);
    },
    query() {
      if (this.companyId) {
        this.dataToQuery.companyId = this.companyId
        // this.dataToQuery.ifReport = '0'
      }
      this.queryAjax();
    },

    submit(name) {
      if (this.dataToView.items.length < 1) {
        this.$Message.warning('危化品至少填报一条');
      } else {
        this.submitAjax(name);
      }
    },

    setCompanyId(data) {
      if (data && data instanceof Array && data.length > 0) {
        this.$set(this.dataToView, 'companyId', data[data.length - 1])
        this.$set(this.dataToView, 'chargeUser', '')
        this.$set(this.dataToView, 'chargeUserName', '')
        this.setCurrentUserName = {name: ''};
        this.$nextTick(() => {
          this.$refs.userDom.setCurrentInfo();
        })
      }
    },
    createEmptyDataToAdd() {
      return {
        createDate: new Date(),
        createUserId: this.currentUser.userId,
        createUserName: this.currentUser.userName,
        areaCovered: '',
        // hcmCount: '',
        hcmCountPro: 'kg',
        id: this.get_uuid(),
        idFiles: [],
        items: []
      }
    },
    async afterDataToViewInit() {
      await this.getFiles1('id', 'hcmInfo');
    },

    async editData(data) {
      //修改页面
      this.mode = 'edit'
      let dataToView = _deepclone(data.row);
      this.dataToView = dataToView
      if (this.afterDataToViewInit instanceof Function) {
        await this.afterDataToViewInit()
      }
      this.setCurrentUserName = {name: this.dataToView.chargeUserName};
      this.dialogShow = true;
      setTimeout(() => {
        this.dialogVisibleChangeHandele(this.dialogShow)
        this.$refs.userDom.setCurrentInfo();
      }, 100)

    },

  },
  watch: {}
}
</script>

<style lang='css' scoped>
@import '../../../index.css';
</style>
